﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using CNVP.Framework;
using CNVP.Framework.Helper;
using CNVP.Config;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;
using System.Reflection;

namespace CNVP.JShop.Web.Admin.Template
{
    public partial class JShopAjax : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "application/json";
            string Action = Public.FilterSql(Request.Params["Action"]);
            string ID = Request.Params["ID"];
             string typeID = Request.Params["typeID"];
            switch (Action)
            {
                case "ColumnLeft":
                    ColumnOperate("JCmsColumn", "ColumnLeft", "Column.aspx", true, typeID);
                    break;
                case "ColumnMove":
                    ColumnOperate("JCmsColumn", "ColumnMove", "Operate/ColumnMove.aspx", true, typeID);
                    break;
                case "ColumnSet":
                    ColumnOperate("TemplateSet", "ColumnSet", "Operate/ColumnSet.aspx", true, typeID);
                    break;
                case "TemplateSelect":
                    TemplateSelect();
                    break;
                case "TemplateSelectDel":
                    TemplateSelectDel();
                    break;
                case "GetUnitStyleUrl":
                    GetUnitStyleUrl();
                    break;
            }
        }
        #region "栏目操作"
        /// <summary>
        /// 栏目导航
        /// </summary>
        private void ColumnOperate(string Permissions, string Operate, string Url, bool ShowAll, string typeID)
        {
            Response.Write(Common.ColumnOperate(Permissions, Operate, Url, ShowAll, typeID));
            Response.End();
        }
        #endregion
        #region "选择模板"
        private void TemplateSelect()
        {
            string ParentID = Request.Params["ParentID"];
            string TemplateType = Request.Params["TemplateType"];
            string FileID = Request.Params["FileID"];
            if (string.IsNullOrEmpty(ParentID) | (!Public.IsNumber(ParentID)))
            {
                ParentID = "0";
            }
            if (string.IsNullOrEmpty(TemplateType) | (!Public.IsNumber(TemplateType)))
            {
                TemplateType = "0";
            }
            string TemplateUrl = "";
            TemplateUrl = FileID;
            CNVP.JShop.BLL.CNVP_Template bll = new CNVP.JShop.BLL.CNVP_Template();
            bll.TemplateAdd(Convert.ToInt32(ParentID), Convert.ToInt32(TemplateType), UIConfig.TemplateUse, TemplateUrl);
            Response.Write("{\"returnval\":\"恭喜，选择模板操作成功！\"}");
            Response.End();
        }
        #endregion
        #region "删除模板"
        private void TemplateSelectDel()
        {
            string TemplateID = Request.Params["TemplateID"];
            if (string.IsNullOrEmpty(TemplateID) | (!Public.IsNumber(TemplateID)))
            {
                TemplateID = "0";
            }
            CNVP.JShop.BLL.CNVP_Template bll = new CNVP.JShop.BLL.CNVP_Template();
            bll.TemplateDel(Convert.ToInt32(TemplateID));
            Response.Write("{\"returnval\":\"恭喜，删除模板操作成功！\"}");
            Response.End();
        }
        #endregion
        #region "获取单元链接"
        private void GetUnitStyleUrl()
        {
            string StyleID = Request.Params["StyleID"];
            if (string.IsNullOrEmpty(StyleID) | (!Public.IsNumber(StyleID)))
            {
                StyleID = "0";
            }
            string StrUrl = "";
            CNVP.JShop.BLL.CNVP_UnitsInfo bll = new CNVP.JShop.BLL.CNVP_UnitsInfo();
            DataTable Dt = bll.GetUnitStyleProperty(Convert.ToInt16(StyleID));
            if (Dt == null || Dt.Rows.Count == 0)
            {
                Response.Write("{\"returnval\":\"#\"}"); ;
            }
            else
            {
                StrUrl = Dt.Rows[0]["ItemUrl"].ToString();
                Response.Write("{\"returnval\":\"" + StrUrl + "\"}");
            }
            Response.End();
        }
        #endregion
    }
}